package we3d.core.culling 
{
	import we3d.core.Object3d;
	import we3d.core.Camera3d;
	import we3d.math.Matrix3d;
	
	/**
	* Object culling, camera near and far plane - object sphere.
	*/
	public class ZCulling extends BoundSphere implements IObjectCulling
	{
		public function ZCulling () {}
		
		public function cull (obj:Object3d, cam:Camera3d, cam_cgv:Matrix3d) :Boolean 
		{
			if(bSphere == 0) return true;
			
			var rv:Matrix3d = obj.transform.gv;
			var cgv:Matrix3d = cam.cgv;
			
			var z1:Number = cgv.c*rv.m + cgv.g*rv.n + cgv.k*rv.o + cgv.o + cam._nearClipping;
			
			if(z1 + bSphere < cam._nearClipping) return true;
			if(z1 - bSphere > cam._farClipping) return true;
			
			cam_cgv.concatM4(obj.transform.gv, cam.cgv, cam_cgv);
			
			return false;
		}
		
	}
}